export default {
  namespace: "count",
  state: {
    count: 11112
  },
  effects: {
    *AsyncChangeCount(_, { put }) {
      const value = yield new Promise(resolve => {
        setTimeout(() => {
          resolve(2);
        }, 2000);
      });
      yield put({
        type: "changeCount",
        payload: {
          count: value
        }
      });
    }
  },
  reducers: {
    setCount(state) {
      state.count += 1;
      return { ...state };
    },
    changeCount(state, { payload }) {
      state.count = payload.count;
      return { ...state };
    }
  }
};
